package com.ternnetwork.core.accesscontroll.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ternnetwork.persistence.repository.BaseRepository;
import com.ternnetwork.core.accesscontroll.entity.RescRole;
import com.ternnetwork.core.accesscontroll.entity.RescRoleId;
import com.ternnetwork.core.accesscontroll.enums.ResourcesType;

public interface RescRoleRepository extends BaseRepository<RescRole, RescRoleId> {
	
	/**
	 * 按ID统计
	 * @param id
	 * @return
	 */
	@Query("select count(1) from RescRole where id=?1")
	Long getCountById(RescRoleId id);
	
	
	@Query("from RescRole t where t.role.id=?1 and t.resources.type=?2")
	List<RescRole> findAll(Long roleId,ResourcesType resourcesType);
	
	@Modifying
	@Query("delete from RescRole t where t.role.id=?1")
	Integer deleteAllByRoleId(Long roleId);
	
	@Modifying
	@Query("delete from RescRole t where t.id=?1")
	Integer deleteAllById(RescRoleId id);

}
